package com.jyffeng.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/s6")
public class Servlet06 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应相关api  http/1.1   200/404/405/500
        resp.setStatus(200);

        String info = "<h1>hello servlet06</h1>";
        //设置响应头相关的api
//        resp.setHeader("aaa", "valA");
//        resp.setHeader("Content-Type", "text/html;charset=utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //设置响应体长度
        resp.setContentLength(info.getBytes().length);
        //设置响应体内容相关api
        //获得一个向相应提供输入文本字符输出流
        PrintWriter writer = resp.getWriter();
        writer.write(info);

        //获得一个向响应体中输入二进制信息的字节输出流
//        ServletOutputStream outputStream = resp.getOutputStream();

    }
}
